<template>
  <div class="not-found">
    <div>访问的页面不存在或没有权限访问该页面！ {{ second }} 秒后返回上一页</div>
    <el-button size="large" type="primary" @click="router.go(-1)">立即返回</el-button>
  </div>
</template>
<script setup name="notFound">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
import { stores } from '@/stores/index.js'
const menuStore = stores.useMenuStore()
const router = useRouter()
const second = ref(3)
const timer = ref(null)
onMounted(() => {
  timer.value = setInterval(() => {
    second.value--
    if (second.value <= 0) {
      clearInterval(timer.value)
      router.go(-1)
    }
  }, 1000)
})
onBeforeUnmount(() => {
  // console.log(router.currentRoute.value)
  menuStore.setActiveRoute({
    label: router.currentRoute.value.meta.title,
    path: router.currentRoute.value.path
  })
  clearInterval(timer.value)
})
</script>

<style lang="scss" scoped>
.not-found {
  height: 100%;
  width: 100%;
  font-size: 40px;
  text-align: center;
  padding-top: 200px;
}
</style>
